package persist

import (
	"gitee.com/jnshao/go-start/projects/crawler/engine"
	"gitee.com/jnshao/go-start/projects/crawler/persist"
	"log"

	"gopkg.in/olivere/elastic.v6"
)

type ItemSaverService struct {
	Client *elastic.Client
	Index  string
}

// rpc请求方法
func (s *ItemSaverService) Save(item engine.Item, result *string) error {
	err := persist.Save(s.Client, s.Index, item)
	log.Printf("Item %v saved.", item)
	if err != nil {
		*result = "error"
		log.Printf("Error Saving item %v:%v", item, err)
		return err
	}
	*result = "ok"
	return nil
}
